import { Selector } from '@ngxs/store';
import { SystemState, SystemStateModel } from './system.state';
import * as _ from 'lodash';

export class SystemSelector {
  @Selector([SystemState])
  static list({list}: SystemStateModel) {
    return list;
  }

  @Selector([SystemState])
  static loading({loading}: SystemStateModel) {
    return loading;
  }

  @Selector([SystemState])
  static configList({configList}: SystemStateModel) {
    return configList;
  }

  @Selector([SystemState])
  static canBackup({configList}: SystemStateModel) {
    return _.findIndex(configList, (s: any) => s.isDefault) !== -1;
  }

  @Selector([SystemState])
  static defaultParam({configList}: SystemStateModel) {
    return _.find(configList, (s: any) => s.isDefault);
  }
}
